package com.gxuwz.hmr.project.system.organ.controller;

import java.util.List;

import com.gxuwz.hmr.project.system.organ.domain.Organ;
import com.gxuwz.hmr.project.system.organ.service.IOrganService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.organ.domain.Organ;
import com.ruoyi.project.system.organ.service.IOrganService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 医疗机构管理Controller
 * 
 * @author ruoyi
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/system/organ")
public class OrganController extends BaseController
{
    private String prefix = "system/organ";

    @Autowired
    private IOrganService organService;

    @RequiresPermissions("system:organ:view")
    @GetMapping()
    public String organ()
    {
        return prefix + "/organ";
    }

    /**
     * 查询医疗机构管理列表
     */
    @RequiresPermissions("system:organ:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Organ organ)
    {
        startPage();
        List<Organ> list = organService.selectOrganList(organ);
        return getDataTable(list);
    }

    /**
     * 导出医疗机构管理列表
     */
    @RequiresPermissions("system:organ:export")
    @Log(title = "医疗机构管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Organ organ)
    {
        List<Organ> list = organService.selectOrganList(organ);
        ExcelUtil<Organ> util = new ExcelUtil<Organ>(Organ.class);
        return util.exportExcel(list, "医疗机构管理数据");
    }

    /**
     * 新增医疗机构管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医疗机构管理
     */
    @RequiresPermissions("system:organ:add")
    @Log(title = "医疗机构管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Organ organ)
    {
        return toAjax(organService.insertOrgan(organ));
    }

    /**
     * 修改医疗机构管理
     */
    @GetMapping("/edit/{orginId}")
    public String edit(@PathVariable("orginId") Long orginId, ModelMap mmap)
    {
        Organ organ = organService.selectOrganById(orginId);
        mmap.put("organ", organ);
        return prefix + "/edit";
    }

    /**
     * 修改保存医疗机构管理
     */
    @RequiresPermissions("system:organ:edit")
    @Log(title = "医疗机构管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Organ organ)
    {
        return toAjax(organService.updateOrgan(organ));
    }

    /**
     * 删除医疗机构管理
     */
    @RequiresPermissions("system:organ:remove")
    @Log(title = "医疗机构管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(organService.deleteOrganByIds(ids));
    }
}
